package com.parking.mgr.common.exception.enums;


import com.parking.mgr.common.annotion.ExpEnumType;
import com.parking.mgr.common.constant.ExpEnumConstant;
import com.parking.mgr.common.exception.BaseException;
import com.parking.mgr.common.exception.ServiceException;
import com.parking.mgr.common.exception.asserts.Assertion;
import com.parking.mgr.common.factory.ExpEnumCodeFactory;

/**
 * @ClassName StatusExceptionEnum
 * @Description 状态枚举
 * @Auther: zhijianpu
 * @Date: 2023/5/19
 */
@ExpEnumType(module = ExpEnumConstant.CORE_MODULE_EXP_CODE, kind = ExpEnumConstant.STATUS_EXCEPTION_ENUM)
public enum StatusExceptionEnum implements IBaseExceptionEnum, Assertion {

    /**
     * 请求状态值为空
     */
    REQUEST_EMPTY(1, "请求状态值为空"),

    /**
     * 请求状值为非正确状态值
     */
    NOT_WRITE_STATUS(2, "请求状态值不合法"),

    IS_NOT_UNIQUE_KEY(4, "我的key有重复值"),
    I18N_MESSAGE_IS_NOT_UNIQUE_KEY(1, "i18n_message_is_not_unique_key"),

    /**
     * 更新状态失败，试图更新被删除的记录
     */
    UPDATE_STATUS_ERROR(3, "更新状态失败，您试图更新被删除的记录");


    private final Integer code;

    private final String message;

    StatusExceptionEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public Integer getCode() {
        return ExpEnumCodeFactory.getExpEnumCode(this.getClass(), code);
    }

    @Override
    public String getMessage() {
        return message;
    }

    @Override
    public BaseException onAssertFailed(String errorMessage) {
        if (errorMessage == null || errorMessage.isEmpty()) {
            return new ServiceException(this);
        } else {
            return new ServiceException(this.getCode(), errorMessage);
        }
    }

}
